import { InjectionKey } from 'vue';
import { v4 as uuidv4 } from 'uuid';

export const conditionsKey = Symbol() as InjectionKey<any>;

export const addId = (obj?: any) => {
  if (obj) {
    if (Array.isArray(obj)) {
      for (const iterator of obj) {
        if (iterator && !iterator.hasOwnProperty('id')) iterator.id = uuidv4();
      }
      return obj || [];
    } else if (typeof obj === 'object') {
      if (!obj.hasOwnProperty('id')) obj.id = uuidv4();
      return obj || {};
    }
  }
};
